﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim.Basics;

namespace DynSim.EntityFramework
{
    [Serializable]
    public class EntityCollection : List<IEntity>
    {
        public void InitializeAll()
        {
            foreach (IEntity entity in this)
            {
                entity.Initialize();
            }
        }

        public void UpdateAll(GameTime gameTime, Camera camera)
        {
            foreach (IEntity entity in this)
            {
                entity.Update(gameTime);
            }
        }

        public void DrawAll(GameTime gameTime)
        {
            foreach (IEntity entity in this)
            {
                entity.Draw(gameTime);
            }
        }

        public void AddAndInitialize(IEntity entity)
        {
            entity.Initialize();
            this.Add(entity);
        }

        public void AddRangeAndInitialize(IEntity[] entities)
        {
            foreach (IEntity item in entities)
                item.Initialize();

            this.AddRange(entities);
        }

        public IEntity GetEntityFromName(string name)
        {
            foreach (IEntity item in this)
            {
                if (item.name == name)
                    return item;
            }

            return null;
        }

        public void RemoveEntity(string name)
        {
            int i = 0;
            while (i != this.Count -1)
            {
                if (this[i].name == name)
                    this.RemoveAt(i);
                else
                    ++i;
            }
        }
    }
}